package week07.springjdbc;

import org.springframework.data.relational.core.conversion.MutableAggregateChange;
import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author edward
 * @since 2021-08-08
 */
@Component
public class ProductBeforeSaveCallback implements BeforeSaveCallback<Product> {

    @Override
    public Product onBeforeSave(Product aggregate, MutableAggregateChange<Product> aggregateChange) {
        aggregate.setProductId(UUID.randomUUID().toString());
        return aggregate;
    }
}
